package server.container;

import server.pojo.Request;
import server.pojo.Response;
import server.connector.MyConnector;

import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;

public class MyService implements BaseContainer {

    List<MyEngine> list = new LinkedList<>();

    List<MyConnector> listc = new LinkedList<>();

    public MyService(MyServer myServer) {
        myServer.add(this);
    }

    public void add(MyEngine myEngine) {
        list.add(myEngine);
    }

    public void add(MyConnector myConnector) {
        listc.add(myConnector);
    }

    public void invoke(Request request, Response response) {
        list.forEach(new Consumer<MyEngine>() {
            @Override
            public void accept(MyEngine myEngine) {
                myEngine.invoke(request, response);
            }
        });
    }

    public void start() {
        listc.forEach(new Consumer<MyConnector>() {
            @Override
            public void accept(MyConnector myConnector) {
                myConnector.start();
            }
        });
    }


}
